﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoPhongLapLich
{
    class Program
    {
        static void Main(string[] args)
        {
            Timer t = new Timer();
            
            Cpu cpu = new Cpu(3);
            Tracker tTracker = new Tracker(t);
            StartQueue startQueue = new StartQueue(tTracker);
            Resource1 resource1 = new Resource1();
            Resource2 resource2 = new Resource2();

            cpu.AddLink(resource1); cpu.AddLink(resource2); cpu.AddLink(tTracker);// Luu y tracker co do uu tien thap hon nen them vao sau cung
            tTracker.AddLink(cpu);
            resource1.AddLink(tTracker);
            resource2.AddLink(tTracker);
            startQueue.AddLink(cpu);
            t.Tick += startQueue.Run;
            t.Tick += cpu.Run;
            t.Tick += resource1.Run;
            t.Tick += resource2.Run;

            var a = new List<Process>(startQueue.Processes);

            t.Run();
            
            // In kq
            foreach (var p in a)
            {
                Console.WriteLine("Process {0} : {1}",p.Id,p.TimeWait);
            }
            Console.ReadLine();
        }
    }
}
